<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<title>历史建设阶段</title>
<base href="<%=basePath%>">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<link rel="stylesheet" href="css/vivo.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="js/bootstrap2/css/bootstrap.min.css">
<link rel="stylesheet" href="css/common.css">

<script src="js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="js/form.js"></script>
<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script>
<script language="javascript" type="text/javascript"
	src="<%=basePath%>js/My97DatePicker/WdatePicker.js"></script>

<style type="text/css">
.style_btn {
	margin: 5px;
}
</style>
<script type="text/javascript">
	$(function(){
		
		
		getBuildStage();
	})
	
	//获取建筑数量列表（建筑名、楼号）
	function getBuildStage() {
		var url = "project/approval/getBuildStageHistoryById";
		//paid:立项id
		var id = '${id}';
		$.getJSON(url, {
			id : id
		}, function(data, status) {
			console.log(data);
			if (status == "success") {
				var $t,v;
				if(data != null){
					$("#buildStage input[name='buildDate']").val(new Date(data.buildDate).format('yyyy-MM-dd hh:mm:ss'));
					$("#buildStage input[name='buildName']").val(data.buildName);
					$("#buildStage input[name='buildUnit']").val(data.buildUnit);
					$("#buildStage input[name='allJobUnit']").val(data.allJobUnit);
					$("#buildStage input[name='allJobScope']").val(data.allJobScope);
					$("#buildStage input[name='projectAssociate']").val(data.projectAssociate);
					$("#buildStage input[name='businessUnit']").val(data.businessUnit);
					$("#buildStage input[name='superviseUnit1']").val(data.superviseUnit);
					$("#buildStage input[name='subpackageId']").val(data.subpackageId);
					$("#buildStage input[name='buId']").val(data.id);
					//添加分包div模板并赋值
					if(data.subpackage!=null){
						console.log(data.subpackage);
						for(var i=0;i<data.subpackage.length;i++){
							addDiv2();
						}
						$t = $("#div_build table");
						for(var i=0;i<data.subpackage.length;i++){
							v=$t[i];
							$(v).find("input[name='superviseUnit']").val(data.subpackage[i].superviseUnit);
							$(v).find("input[name='businessUnit']").val(data.subpackage[i].businessUnit);
							$(v).find("input[name='unitName']").val(data.subpackage[i].unitName);
							$(v).find("input[name='unitTel']").val(data.subpackage[i].unitTel);
							$(v).find("input[name='principalTel']").val(data.subpackage[i].principalTel);
							$(v).find("textarea[name='remark']").val(data.subpackage[i].remark);
							$(v).find("input[name='id']").val(data.subpackage[i].id);
						}
					}
					//隐藏按钮
					$("#buildStage #btn_div2").show();
					$("#buildStage #btn_div1").hide();
					$("#buildStage").find("input,textarea").attr("readonly",true);
					$("#buildStage").find(".addbtn").attr("disabled",true);
					$("#buildStage").find(".icon-fullscreen").hide();
				}
			}
		});
	}
	
	
</script>
</head>
<body>
	<form class="cmxform" id="buildStage" method="post"
		action="project/approval/addBuild" onsubmit="return false">
		<div style="padding:0px 10px">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h5 class="panel-title" style="font-weight: bold;">建设阶段</h5>
				</div>
				<div class="panel-body">
					<input type="hidden" name="buId" id="entityId_buId"/><!-- 实体id -->
					<table cellpadding="10" cellspacing="5" class="mytable">
						<tr>
							<td width="90">建设时间</td>
							<td width="260"><input name="buildDate" class="Wdate" onClick="WdatePicker()" /></td>
							<td width="90">建设名称</td>
							<td><input name="buildName" value="" /></td>
							<td width="90">建设单位</td>
							<td><input name="buildUnit" value="" class="input_name"/></td>
						</tr>
					</table>
					<fieldset>
						<legend>施工单位</legend>
						<table>
							<tr>
								<td width="90"><span class="style_btn">总包单位</span></td>
								<td width="290"><input name="allJobUnit" value="" /></td>
								<td width="90"><span class="style_btn">总包范围</span></td>
								<td><input name="allJobScope" value="" /></td>
							</tr>
							<tr>
								<td><span class="style_btn">项目经理</span></td>
								<td><input name="projectAssociate" value="" /></td>
								<td><span class="style_btn">业务单位</span></td>
								<td><input name="businessUnit" style="margin-right:15px;" value="" />
								</td>
							</tr>
						</table>
						<!-- 动态div start -->
						<div id="div_build"></div>
						<!-- 动态div end-->
					</fieldset>
					<p style="margin:10px 0px 0px 0px;">
						<span>监理单位</span> <span style="margin:0px 40px;"><input value="" name="superviseUnit1" /> </span>
					</p>
				</div>
			</div>
			<input type="hidden" id="entityId_subpackageId" name="subpackageId" value=""/><!-- 施工单位外键id -->
			<div style="width:100%;text-align:center; padding-top:0px">
			
			</div>
		</div>
	</form>

	<script type="text/javascript">
		function addDiv2() {
			var node;
			node = $("#build_templete").html();
			var oTest = $("#div_build");
			oTest.append(node);
		}
	
	</script>

	<!-- 模板div start -->
	<div id="build_templete" style="display:none;">
		<div class="style_border_tem">
			<table cellpadding="10" cellspacing="5" class="mytable">
				<tr>
					<td width="90"><span>分包单位</span><input type="hidden" id="entityId_id" name="id" value="" /></td>
					<td><input id="" name="superviseUnit" value="" /></td>
					<td colspan="2" valign="top" align="right"><a
						href="javascript:void(0)" onclick="delTrDivBuild(this)"> <i
							class="icon-fullscreen"></i>
					</a></td>
				</tr>
				<tr>
					<td width="90"><span>业务单位</span></td>
					<td width="320"><input id="" name="businessUnit" value="" /></td>
					<td width="90"><span>单位名称</span></td>
					<td><input id="" name="unitName" value="" /></td>
				</tr>
				<tr>
					<td width="90"><span>单位联系</span></td>
					<td width="320"><input id="" name="unitTel" value="" /></td>
					<td width="90"><span>负责人联系</span></td>
					<td><input id="" name="principalTel" value="" /></td>
				</tr>
				<tr>
					<td>备注</td>
					<td colspan="3"><textarea name="remark" rows="3" cols="70" style="width:70%;"></textarea></td>
				</tr>
			</table>
		</div>
	</div>
	<!-- 模板div end -->
</body>
</html>

